from django.db import models
from DjangoUeditor.models import UEditorField
from django.contrib.auth.models import User
from django.conf import settings

# Create your models here.

class Article(models.Model):
	'''文章模型'''
	id = models.AutoField(primary_key=True)
	article_name = models.CharField(max_length=32,verbose_name="标题")
	classification_id = models.ForeignKey('ClassIfication',verbose_name='分类',default=5)
	author = models.ForeignKey(to=User,verbose_name='作者',default=1)
	tags_id = models.ManyToManyField(to='ArticleTags',verbose_name='标签',null=True)
	content = UEditorField('内容', height=300, width=1000,
	                       default=u'', blank=True, imagePath="uploads/images/",
	                       toolbars='besttome', filePath='uploads/files/')
	create_time = models.DateTimeField(verbose_name='创建时间',auto_now_add=True)
	end_time = models.DateTimeField(verbose_name='最后修改时间',auto_now=True)
	def __str__(self):
		return self.article_name
	class Meta:
		db_table = 'blog_article'
		verbose_name_plural = '文章管理'

class ClassIfication(models.Model):
	'''文章分类'''
	id = models.AutoField(primary_key=True)
	classname = models.CharField(verbose_name='文章分类',max_length=18)
	def __str__(self):
		return self.classname
	class Meta:
		db_table = 'blog_classification'
		verbose_name_plural = '分类管理'

class ArticleTags(models.Model):
	'''文章标签'''
	id = models.AutoField(primary_key=True)
	tags = models.CharField(max_length=18,verbose_name='标签')
	def __str__(self):
		return self.tags
	class Meta:
		db_table = 'blog_article_tags'
		verbose_name_plural = '标签管理'